<template>
  <div class="container">
    <div class="header">
      <h1>欢迎使用惊喜一餐！</h1>
      <div class="search-bar">
        <el-input v-model="input" style="width:auto" aria-placeholder="可以在这输入您想找的餐厅"/>
        <el-button class="serach">搜索</el-button>
      </div>
    </div>
    <div class="main-content">
      <div>
         <el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">
        <el-radio-button :value="false">expand</el-radio-button>
        <el-radio-button :value="true">collapse</el-radio-button>
        </el-radio-group>
      </div>
     <div id="body">
          <div id="aside">
      <el-menu
        default-active="2"
        class="el-menu-vertical-demo"
        :collapse="isCollapse"
        @open="handleOpen"
        @close="handleClose"
      >
        <!-- <el-sub-menu index="1">
          <template #title>
            <el-icon><location /></el-icon>
            <span>首页</span>
          </template>
          <el-menu-item-group>
            <template #title><span>Group One</span></template>
            <el-menu-item index="1-1">item one</el-menu-item>
            <el-menu-item index="1-2">item two</el-menu-item>
          </el-menu-item-group>
          </el-sub-menu> -->
          <el-menu-item index="1">
            <el-icon><icon-menu /></el-icon>
            <template #title>首页</template>
          </el-menu-item>
          <el-menu-item index="2">
            <el-icon><icon-menu /></el-icon>
            <template #title>餐厅详情页</template>
          </el-menu-item>
          <el-menu-item index="3">
            <el-icon><document /></el-icon>
            <template #title>用户信息页</template>
          </el-menu-item>
          <!-- <el-menu-item>
            <el-icon><setting /></el-icon>
            <template #title>Navigator Four</template>
          </el-menu-item> -->
      </el-menu>
      </div>
      <div id="main">
        <el-col v-for="restaurant in recommendedRestaurants" :key="restaurant.id" :span="8">
          <el-card class="restaurant-card">
            <img :src="restaurant.image" class="restaurant-image" />
            <div class="restaurant-info">
            <h3 class="restaurant-name">{{ restaurant.name }}</h3>
            <p class="restaurant-mark">评分:{{ restaurant.rating }}</p>
            <p class="restaurant-describe">{{ restaurant.address }}</p>
            <el-button type="primary" @click="viewDetails(restaurant.id)">查看详情</el-button>
            </div>
            </el-card>
          </el-col>

          <!-- <el-card  style="max-width: 400px;">
          <template #header>Yummy hamburger</template>
          <img
              src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"
              style="width: auto"
          />
         </el-card> -->

          <!-- <el-card  style="max-width: 400px;">
          <template #header>Yummy hamburger</template>
          <img
              src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"
              style="width: auto"
          />
         </el-card> -->

        
      </div>
     </div>
      
       
    </div>
  </div>
</template>

<script lang="ts" setup>
  import {ref} from 'vue'
  import {
    Document,
    Menu as IconMenu,
    Location,
    Setting,
  }from '@element-plus/icons-vue'
  import { useRouter } from 'vue-router';
//  import { createRouter } from 'vue-router'

  
  const input=ref('')
  const isCollapse=ref(true)
  const handleOpen=(key:string,keyPath: string[])=>{
    console.log(key,keyPath)
  }
  const handleClose=(key: string,keyPath:string[])=>{
    console.log(key,keyPath)
  }
  
  const recommendedRestaurants =ref([
    {
      id: 1,
      name: '地锅鸡',
      rating: 5.0, 
      address: "花津南路翰林公馆", 
      image: 'src/static/diguoji.jpg'
    },
    {
      id: 2,
      name: '花味烤肉',
      rating: 4.7, 
      address: "苏宁广场7楼", 
      image: 'src/static/huaweikaorou.jpg'
    },
    {
      id: 3,
      name: '锅包肉',
      rating: 4.8, 
      address: "中央城财富街", 
      image: 'src/static/guobaorou.jpg'
    }
  ])
  const router = useRouter()

  const viewDetails = (id: number) => {
  router.push({ name: 'restaurant-detail', params: { id: id.toString() } })
}
</script>

<style scoped>
  .el-menu-vertical-demo:not(.el-menu--collapse){
    width: 200px;
    min-height: 4px;
  }
  .container{
    display: flex;
    flex-direction: column;
    align-items:start;
    justify-content: start;
    height:100vh;
    background-color: aliceblue;
    width: 100%;
  }
  .search-bar {
  display: flex;
  align-items: center;
  gap: 10px; /* 调整输入框和按钮之间的间距 */
  }

  .header {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center; 
    gap: 20px;
    padding: 20px 0;
  }
  h1{
    text-align: center; 
    color:cadetblue;
  }
  /* .search{

  } */

  .menu {
    width: 100%;
    max-width: 300px;
  }
  #aside{
      display: inline-block;
  }

  #main{
    margin-left: 10px;
    /* display: inline-flex;   */
    display: flex;
    flex-direction: row;
    flex-wrap: wrap; 
    justify-content: space-around;
    max-height: 400px;

  }

.restaurant-card{
  max-width: 320px;
  margin-left:10px;
  margin-right: 10px;
}
.restaurant-image{
  width:100%;
  height: 150px;
  object-fit: cover;/*保持图片比例 */
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}
.restaurant-name{
  font-size: 16px;
  margin:0;
}
.restaurant-mark,
.restaurant-describe{
  font-size: 12px;
  margin: 0;
}
#body{
    display: flex;
    flex-direction:row;
    justify-content: start;
    align-content: baseline;
}
</style>